home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CURSOR.c
- Folder: RUNTIME
- (c) Encore Développement, SARL, 1992-94
- */
-
- #include "Memory.h"
- #include "QuickDraw.h"
- #include "Retrace.h"
-
- #include "Key.h"
-
- extern const keyID K_DATA;
- extern const keyID K_ID;
-
- extern const keyID K_COUNT;
- extern const keyID K_GETAT;
-
- void CursorLoad(key* the)
- {
- short anID;
- CCrsrHandle aCCrsrHandle;
-
- anID = keyToInteger(keyGet(the[SELF], K_ID));
- aCCrsrHandle = GetCCursor(anID);
- keyIfNULL(aCCrsrHandle);
- keyPut(the[SELF], K_DATA, keyFromHandle(aCCrsrHandle));
- }
-
- void CursorSet(key* the)
- {
- CCrsrHandle aCCrsrHandle;
-
- aCCrsrHandle = (CCrsrHandle)keyToHandle(keyGet(the[SELF], K_DATA));
- keyCheck(aCCrsrHandle != NULL);
- SetCCursor(aCCrsrHandle);
- }
-
- void CursorUnload(key* the)
- {
- CCrsrHandle aCCrsrHandle;
-
- aCCrsrHandle = (CCrsrHandle)keyToHandle(keyGet(the[SELF], K_DATA));
- keyCheck(aCCrsrHandle != NULL);
- DisposCCursor(aCCrsrHandle);
- keyPut(the[SELF], K_DATA, keyVoid);
- }
-
- typedef struct {
- #ifdef applec
- long globalA5;
- long localA5;
- #endif
- VBLTask task;
- short running;
- short index;
- short count;
- CCrsrPtr cursors[64];
- } SpinRecord, *SpinPtr;
-
- SpinRecord gSpinRecord;
-
- #ifdef applec
- pascal long GetA0() = { 0x2e88 };
- pascal long GetA5() = { 0x2e8d };
- #endif
-
- pascal void SpinVBLTask()
- {
- #ifdef applec
- SpinPtr aSpinPtr = (SpinPtr)(GetA0() - (sizeof(long) * 2));
- aSpinPtr->localA5 = SetA5(aSpinPtr->globalA5);
- #endif
- #ifdef powerc
- SpinPtr aSpinPtr = &gSpinRecord;
- #endif
- aSpinPtr->task.vblCount = 10;
- aSpinPtr->index++;
- if (aSpinPtr->index == aSpinPtr->count) {
- aSpinPtr->index = 0;
- }
-
- /*
- Use the b&w cursor inside the locked color cursor handle
- so it does not move memory...
- */
-
- SetCursor((Cursor*)&((aSpinPtr->cursors[aSpinPtr->index])->crsr1Data));
- #ifdef applec
- SetA5(aSpinPtr->localA5);
- #endif
- }
-
- void SpinIsRunning(key* the)
- {
- the[RESULT] = keyFromBoolean(gSpinRecord.running);
- }
-
- void SpinStart(key* the)
- {
- static VBLUPP aVBLUPP = NULL;
-
- short aCount, anIndex;
- Handle aHandle;
-
- if (aVBLUPP == NULL) {
- aVBLUPP = NewVBLProc(SpinVBLTask);
- }
-
- aCount = keyToInteger(keyCall0(the[SELF], K_COUNT));
- for (anIndex = 0; anIndex < aCount; anIndex++) {
- the[RESULT] = keyCall1(the[SELF], K_GETAT, keyFromInteger(anIndex + 1));
- aHandle = keyToHandle(keyGet(the[RESULT], K_DATA));
- HLock(aHandle);
- gSpinRecord.cursors[anIndex] = (CCrsrPtr)*aHandle;
- }
-
- #ifdef applec
- gSpinRecord.globalA5 = GetA5();
- #endif
- gSpinRecord.task.qType = vType;
- gSpinRecord.task.vblAddr = aVBLUPP;
- gSpinRecord.task.vblCount = 10;
- gSpinRecord.task.vblPhase = 0;
- gSpinRecord.index = 0;
- gSpinRecord.count = aCount;
- if (VInstall((QElemPtr)&(gSpinRecord.task)) == noErr) {
- gSpinRecord.running = 1;
- }
- }
-
- void SpinStop(key* the)
- {
- short aCount, anIndex;
- Handle aHandle;
-
- if (VRemove((QElemPtr)&(gSpinRecord.task)) == noErr) {
- gSpinRecord.running = 0;
- }
- aCount = keyToInteger(keyCall0(the[SELF], K_COUNT));
- for (anIndex = 0; anIndex < aCount; anIndex++) {
- the[RESULT] = keyCall1(the[SELF], K_GETAT, keyFromInteger(anIndex + 1));
- aHandle = keyToHandle(keyGet(the[RESULT], K_DATA));
- HUnlock(aHandle);
- gSpinRecord.cursors[anIndex] = NULL;
- }
- }
-
- void CursorsShow(key *the)
- {
- if (keyIsTrue(the[ARGUMENT(1)]))
- ShowCursor();
- else
- HideCursor();
- }
-